package num1;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;

/**
 * @author : DuJiabao
 * @Project : sword-finger-offer
 * @Time : 2021/5/9 1:26
 * @Desc :
 */
public class Solution {
  public int[] twoSum(int[] nums, int target) {
    HashMap<Integer, Integer> map = new HashMap<>();

    for (int i = 0; i < nums.length; i++) {
      Integer index = map.get(target - nums[i]);
      if (index != null && index != i)
        return new int[]{i, index};
      map.put(nums[i], i);
    }
    return new int[0];
  }

  public static void main(String[] args) {
    int[] res = new Solution().twoSum(new int[]{3, 2, 4}, 6);
    System.out.println(Arrays.toString(res));
  }
}
